package com.liushao.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liushao.entity.UserInfo;
import com.liushao.entity.vo.*;
import com.liushao.result.Result;
import com.liushao.service.UserInfoService;
import com.liushao.util.JwtUtils;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author chen
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {


    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

  //  http://localhost/admin/core/userInfo/list/1/10
    @ApiOperation("获取会员分页列表")
    @GetMapping("/list/{page}/{limit}")
    public Result listPage(
            @ApiParam(value = "当前页码",required = true)
            @PathVariable Long page,
            @ApiParam(value = "每页记录数",required = true)
            @PathVariable Long limit,
            @ApiParam(value = "查询对象",required = false)
             UserInfoQuery userInfoQuery
            ){
          //mp中的分页类
        Page<UserInfo> pages = new Page<>(page,limit);

        IPage<UserInfo> infoIPage= userInfoService.listPage(pages,userInfoQuery);

        return Result.ok().data("pageModel",infoIPage);
    }


   // http://localhost/admin/core/userInfo/lock/11/0
    @ApiOperation("会员锁定")
    @PutMapping("/lock/{id}/{status}")
    public Result lock(
            @ApiParam(value = "用户id",required = true)
            @PathVariable("id") Long id,
            @ApiParam(value = "用户状态 0 锁定  1 解锁",required = true)
            @PathVariable("status") Integer status
    ){
        userInfoService.lock(id,status);
        return  Result.ok().message(status==1?"解锁成功":"锁定成功");
    }
}

